package com.gareve.RainScene.models;

import com.badlogic.gdx.math.Rectangle;

public abstract class SceneObject {
	public Rectangle shape;
	private boolean isAlive;
	
	private float keyFrameTime;
	private float keyFramePeriod;
	public int keyFrame;
	private int frameCount;

	public SceneObject(float x,float y,float width,float height,float keyFramePeriod,int frameCount){
		shape = new Rectangle(x, y, width, height);
		
		this.keyFramePeriod = keyFramePeriod;
		this.frameCount = frameCount;
		keyFrameTime = 0f;
		keyFrame = 0;
		
		isAlive = true;
	}
	
	public boolean isAlive() {
		return isAlive;
	}
	public void setAlive(boolean isAlive) {
		this.isAlive = isAlive;
	}
	
	public void kill(){
		this.isAlive = false;
	}
	
	public void addAnimationTime(float delta){
		keyFrameTime += delta;
		if(keyFrameTime > keyFramePeriod){
			keyFrameTime -= (Math.floor(keyFramePeriod) / keyFrameTime) * keyFramePeriod;
			keyFrame = (keyFrame + 1) % frameCount;
		}
	}
}
